// pages/goodsDetails/goodsDetails.js
var util = require('../../utils/util.js');
var wxParse = require('../../utils/wxParse/wxParse.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    max_price: 0,
    spnum: 1,
    unit_price:0,
    goods_imgs: [
      { url: '../../images/new/7.jpg' },
      { url: '../../images/new/7.jpg' },
      { url: '../../images/new/7.jpg' },
    ],
    aaa: { name: '规格1', specid: '5', stock: 0, max_price: '1000' },

    infor: [
      {
        max_price: '1122',
        name: '车载充电器',
        stock: '12'
      }
    ],
    gid:0,
    article:'',
    defaultAddress:[]
  },
 
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = options.id;
    this.setData({
      gid:id
    })
  },
  goodsDetail: function (id) {
    var that = this;
    util.commonRequest('goodDetail', 'post', {gid:id}, function (res) {
      var data = res.data.data.data;
      if (res.data.code == 200) {
        that.setData({
          goods_imgs: data.goods_banner,
          name:data.name,
          max_price:data.jifen,
          unit_price: data.unit_price,
          goods_img: data.goods_img,
          stock: data.stock,
          defaultAddress:res.data.data.address

        })

        // var that = this;
        var article = data.detail;
        
        if(article == ''){
          article = "<p>暂无详情</p>";
        }
        wxParse.wxParse('article', 'html', article, that);

      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
    // this.goodsDetail(this.data.gid);

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  showjrshop:function(){
    wx.navigateTo({
      url: '../yuyue/index',
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})